package cn.zt.ztzx.service.impl;

import cn.zt.ztzx.model.vo.common.Result;
import cn.zt.ztzx.model.vo.common.ResultCodeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.zt.ztzx.domain.ShopType;
import cn.zt.ztzx.service.ShopTypeService;
import cn.zt.ztzx.mapper.ShopTypeMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86182
* @description 针对表【shop_type】的数据库操作Service实现
* @createDate 2024-09-20 09:37:33
*/
@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType>
    implements ShopTypeService{
    //商品分类列表展示   分页实现 支持按类别编号、类别名称和父类编号三个条件查询  模糊查询
    @Override
    public Result shopList(Integer pageNum, Integer pageSize, ShopType shopType) {
        Page<ShopType> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<ShopType> wrapper = Wrappers.<ShopType>lambdaQuery().like(StringUtils.checkValNotNull(shopType.getBid()), ShopType::getBid, shopType.getBid())
                .like(StringUtils.checkValNotNull(shopType.getType()), ShopType::getType, shopType.getType())
                .like(StringUtils.checkValNotNull(shopType.getParentBid()), ShopType::getParentBid, shopType.getParentBid());
        this.page(page,wrapper);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result findByLevel(String level) {
        List<ShopType> list = this.list(Wrappers.<ShopType>lambdaQuery().eq(ShopType::getLevel,level));
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result addshopType(ShopType shopType) {
        boolean save = this.save(shopType);
        return save ? Result.build(null, ResultCodeEnum.SUCCESS):Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    @Override
    public Result deleteshopType(Integer id) {
        boolean b = this.removeById(id);
        return b ? Result.build(null, ResultCodeEnum.SUCCESS):Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    @Override
    public Result updateshopType(ShopType shopType) {
        boolean b = this.updateById(shopType);
        return b ? Result.build(null, ResultCodeEnum.SUCCESS):Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }
}




